﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;

namespace XISoft.AppCreator.Util.Common
{
    public class DllLoader
    {
        /// <summary>
        /// The assembly we need.
        /// </summary>
        private Assembly assembly = null;

        public void loadLibrary(String fullName)
        {
            try
            {
                this.assembly = Assembly.LoadFrom(fullName);
            }
            catch (NullReferenceException e)
            {
                LogHelper.Trace(e);
                throw e;
            }
        }

        public object newInstance(string ClassName)
        {
            try
            {
                Type pgmType = null;
                if (this.assembly != null)
                {
                    pgmType = this.assembly.GetType( ClassName, true, true);
                }
                else
                {
                    pgmType = Type.GetType(ClassName, true, true);
                }
                //if(pgmType.Namespace =Namespace)
                return Activator.CreateInstance(pgmType);
            }
            catch(Exception e)
            {
                LogHelper.Trace(e);
            }
            return null;
        }
    }
}
